//
//  LZMyChangeInfoViewController.m
//  laziz_Consumer
//
//  Created by ZhaoDongBo on 2016/10/28.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZMyChangeInfoViewController.h"
#import "LZMyChangeNickNameView.h"
#import "LZMyChangeInfoView.h"
#import "LZMyChangeMobileView.h"
#import "LZMyChangeLinkAccount.h"
#import "LZActionSheet.h"
#import "LZAlertView.h"

#import "LZMyPersonInfoViewController.h"
#import "LZAreaCodeViewController.h"

#import "UINavigationBar+BackgroundColor.h"
#import "UIViewController+NavigationItemSetting.h"
#import "GVUserDefaults+LZProperties.h"
#import "UIView+Rotation.h"
#import "UIViewController+LZRemoveViewController.h"
#import "NSString+LZRegex.h"

#import "Masonry.h"

#import "LZUserModel.h"
#import "LZThirdPartyAccountModel.h"
#import "TShareEventHandler.h"
#import "LZRemindView.h"
#import "LZUserInfoPresenter.h"

typedef NS_ENUM(NSInteger ,ValidateNewBindType) {
    ValidateNewBindType_Mobile,
    ValidateNewBindType_Email
};

@interface LZMyChangeInfoViewController ()

@property (nonatomic, strong) LZMyChangeNickNameView    * changeNickNameView;       // 修改昵称
@property (nonatomic, strong) LZMyChangeMobileView      * changeMobileIDCheckView;
@property (nonatomic, strong) LZMyChangeMobileView      * changeMobileLinkNewView;
@property (nonatomic, strong) LZMyChangeLinkAccount     * changeLinkAccount;        // 第三方绑定/解绑
@property (nonatomic, strong) LZMyChangeInfoView    * setPasswordView;              // 设置密码
@property (nonatomic, strong) LZMyChangeInfoView    * changePasswordView;           // 修改密码

@property (nonatomic, strong) LZMyChangeInfoView    * setEmailView;                 // 设置邮箱
@property (nonatomic, strong) LZMyChangeInfoView    * changeEmailView;              // 修改邮箱

@property (strong, nonatomic) UIButton * nav_left_back;
@property (strong, nonatomic) UIButton * nav_right_save;

@property (nonatomic, strong) LZUserInfoPresenter * userInfoPresenter;

@property (nonatomic, strong) NSTimer * timer1;      //验证码倒计时
@property (nonatomic, strong) NSTimer * timer2;      //验证码倒计时

@property (nonatomic, assign) int count1;
@property (nonatomic, assign) int count2;

@property (weak, nonatomic) LZActionSheet * sheetView;

@end

@implementation LZMyChangeInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = UIColorFromRGB(0xf9f7f7, 1);
    
    self.userInfoPresenter = [[LZUserInfoPresenter alloc] init];
    
    if (self.type == LZ_MYCHANGEINFO_TYPE_NICKNAME ||
        self.type == LZ_MYCHANGEINFO_TYPE_SETPASSWORD ||
        self.type == LZ_MYCHANGEINFO_TYPE_CHANGEPASSWORD ||
        self.type == LZ_MYCHANGEINFO_TYPE_SETEMAIL ||
        self.type == LZ_MYCHANGEINFO_TYPE_CHANGEEMAIL) {
        
        [self configNavigationRigihtButton];
    }
    
    [self configNavigationLeftButton];
    [self setup];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
    
    if (self.type == LZ_MYCHANGEINFO_TYPE_LINKACCOUNT) {
        [self.changeLinkAccount reloadData];
    }
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    
    if (self.timer1) {
        [self.timer1 invalidate];
        self.timer1 = nil;
    }
    
    if (self.timer2) {
        [self.timer2 invalidate];
        self.timer2 = nil;
    }
}

- (void)setup {
    
    WS(weakSelf);
    
    if (self.type == LZ_MYCHANGEINFO_TYPE_NICKNAME) {
        
        self.umLogPageViewName = @"修改昵称页面";
        
        self.title = LZLocalizedString(@"change_nickname", @"");
        [self.view addSubview:self.changeNickNameView];
        
        self.changeNickNameView.textField.text = self.currentUserInfo.nickName;
        
        [self.changeNickNameView makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(0);
            make.leading.mas_equalTo(0);
            make.trailing.mas_equalTo(0);
            make.height.mas_equalTo(54);
        }];
    }
    else if (self.type == LZ_MYCHANGEINFO_TYPE_SETPASSWORD) {
        
        self.umLogPageViewName = @"设置密码页面";
        
        self.title = LZLocalizedString(@"set_password", @"");
        [self.view addSubview:self.setPasswordView];
        
        [self.setPasswordView makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(0);
            make.leading.mas_equalTo(0);
            make.trailing.mas_equalTo(0);
            make.height.mas_equalTo(100);
        }];
    }
    else if (self.type == LZ_MYCHANGEINFO_TYPE_CHANGEPASSWORD) {
        
        self.umLogPageViewName = @"更改密码页面";
        
        self.title = LZLocalizedString(@"change_password", @"");
        [self.view addSubview:self.changePasswordView];
        
        [self.changePasswordView makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(0);
            make.leading.mas_equalTo(0);
            make.trailing.mas_equalTo(0);
            make.height.mas_equalTo(145);
        }];
    }
    else if (self.type == LZ_MYCHANGEINFO_TYPE_SETEMAIL) {
        
        self.umLogPageViewName = @"设置邮箱页面";
        
        self.title = LZLocalizedString(@"change_set_email", @"");
        [self.view addSubview:self.setEmailView];
        
        [self.setEmailView makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(0);
            make.leading.mas_equalTo(0);
            make.trailing.mas_equalTo(0);
            make.height.mas_equalTo(145);
        }];
    }
    else if (self.type == LZ_MYCHANGEINFO_TYPE_CHANGEEMAIL) {
        
        self.umLogPageViewName = @"更改邮箱页面";
        
        self.title = LZLocalizedString(@"change_email", @"");
        [self.view addSubview:self.changeEmailView];
        
        [self.changeEmailView makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(0);
            make.leading.mas_equalTo(0);
            make.trailing.mas_equalTo(0);
            make.height.mas_equalTo(145);
        }];
    }
    else if (self.type == LZ_MYCHANGEINFO_TYPE_IDCHECK_MOBILE) {
        
        self.umLogPageViewName = @"更改手机页面";
        
        self.title = LZLocalizedString(@"change_moblie", @"");
        [self.view addSubview:self.changeMobileIDCheckView];
        
        self.changeMobileIDCheckView.getVerificButtonBlock = ^(UIButton * button) {
            [weakSelf getVerifiCodeIdCheck];
        };
        
        self.changeMobileIDCheckView.nextStepButtonBlock = ^(UIButton * button) {
            [weakSelf validateCellPhone];
        };
        
        [self.changeMobileIDCheckView makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(0);
            make.leading.mas_equalTo(0);
            make.trailing.mas_equalTo(0);
            make.bottom.mas_equalTo(0);
        }];
    }
    else if (self.type == LZ_MYCHANGEINFO_TYPE_LINKNEW_MOBILE) {
        
        if (self.currentUserInfo.cellphone.length == 0) {
            self.umLogPageViewName = @"设置手机页面";
            
            self.title = LZLocalizedString(@"personal_set_mobile", @"");
        } else {
            self.umLogPageViewName = @"绑定新手机页面";
            
            self.title = LZLocalizedString(@"change_moblie", @"");
        }
        
        [self.view addSubview:self.changeMobileLinkNewView];
        
        self.changeMobileLinkNewView.getVerificButtonBlock = ^(UIButton * button) {
            //先验证手机号是否存在，再获取验证码
            [weakSelf validateNewBindWithType:ValidateNewBindType_Mobile];
        };
        
        self.changeMobileLinkNewView.nextStepButtonBlock = ^(UIButton * button) {
            [weakSelf linkNewCallPhone];
        };
        
        [self.changeMobileLinkNewView makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(0);
            make.leading.mas_equalTo(0);
            make.trailing.mas_equalTo(0);
            make.bottom.mas_equalTo(0);
        }];
    }
    else if (self.type == LZ_MYCHANGEINFO_TYPE_LINKACCOUNT) {
        
        self.umLogPageViewName = @"第三方绑定页面";
        
        self.title = LZLocalizedString(@"personal_linkaccount", @"");
        [self.view addSubview:self.changeLinkAccount];
        
        self.changeLinkAccount.didSelectRowBlock = ^(NSIndexPath * indexPath, LZThirdPartyAccountModel *model) {
            DLog(@"row:%ld, section:%ld", (long)indexPath.row, (long)indexPath.section);
            
            SSDKPlatformType thirdType;
            
            if (indexPath.row == 0) {   // twitter
                thirdType = SSDKPlatformTypeTwitter;
            }
            else {  // facebook
                thirdType = SSDKPlatformTypeFacebook;
            }
            
            if (model) {
                if (weakSelf.currentUserInfo.cellphone.length == 0 && weakSelf.currentUserInfo.email == 0 && weakSelf.currentUserInfo.thirdParty.count <= 1) {
                    // 如果只用了一个类型的第三方登录，没有绑定手机号、邮箱和另一个第三方登录，则不能解绑(===李建欣说的不要任何提示===2017年3月23日19：05===)
                    return ;
                }
                else {
                    // 解绑
                    [weakSelf.sheetView ReloadTableViewArrayTitle:@[@[LZLocalizedString(@"change_unlink", @"")],@[LZLocalizedString(@"cancel", nil)]]];
                    [weakSelf.sheetView ShowView];
                    
                    weakSelf.sheetView.ClickSheetBlock = ^(NSIndexPath *indexPath, id obj) {
                        if (indexPath.section == 0) {
                            [weakSelf showUnBindThirdPartyAlertWithPartyAccount:model.partyAccount andType:thirdType];
                        }
                    };
                }
            }
            else {
                // 绑定
                [weakSelf getThirdPartyAccountInfo:thirdType];
            }
            
        };
    }
}

- (void)configNavigationLeftButton {
    self.nav_left_back = [UIButton buttonWithType:UIButtonTypeCustom];
    self.nav_left_back.frame = CGRectMake(0, 0, 60, 40);
    [self.nav_left_back addTarget:self action:@selector(navbarBackButtonClickAction:) forControlEvents:UIControlEventTouchUpInside];
    UIImage *image_back = [UIImage imageNamed:@"返回键_头部"];
    [self.nav_left_back setImage:image_back forState:UIControlStateNormal];
    self.nav_left_back.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, CGRectGetWidth(self.nav_left_back.bounds)-image_back.size.width);
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0) {
        [self.nav_left_back setLanguageRotaion];
    }
    
    [self navigationItemSetting:@[self.nav_left_back] type:NAVIGATIONITEMSETTING_LEFT];
}

- (void)configNavigationRigihtButton{
    self.nav_right_save = [UIButton buttonWithType:UIButtonTypeCustom];
    self.nav_right_save.frame = CGRectMake(0, 0, 40, 40);
    self.nav_right_save.titleLabel.font = [UIFont systemFontOfSize:15];
    [self.nav_right_save setTitle:LZLocalizedString(@"change_save", @"") forState:UIControlStateNormal];//@"Save"
    [self.nav_right_save setTitleColor:UIColorFromRGB(0x666666, 1) forState:UIControlStateNormal];
    [self.nav_right_save sizeToFit];
    self.nav_right_save.frame = CGRectMake(0, 0, CGRectGetWidth(self.nav_right_save.bounds), 40);
    [self.nav_right_save addTarget:self action:@selector(navbarSaveButtonClickAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self navigationItemSetting:@[self.nav_right_save] type:NAVIGATIONITEMSETTING_RIGHT];
}

#pragma mark - event

- (void)startTimer1 {
    [self.timer1 invalidate];
    self.count1 = 0;
    self.timer1 = [NSTimer scheduledTimerWithTimeInterval:1
                                                   target:self
                                                 selector:@selector(updateTimeIDCheck)
                                                 userInfo:nil
                                                  repeats:YES];
    
    self.changeMobileIDCheckView.countdownLabel.hidden = NO;
    self.changeMobileIDCheckView.verificCodeButton.hidden = YES;
}

- (void)stopTimer1 {
    [self.timer1 invalidate];
    self.changeMobileIDCheckView.countdownLabel.hidden = YES;
    self.changeMobileIDCheckView.verificCodeButton.hidden = NO;
}

- (void)updateTimeIDCheck
{
    self.count1 ++;
    if (self.count1 >= 60) {
        [self stopTimer1];
        return;
    }
    
    self.changeMobileIDCheckView.countdownLabel.text = [NSString stringWithFormat:@"%is", 60-self.count1];
    
    if (self.count1 == 60) {
        self.changeMobileIDCheckView.countdownLabel.hidden = YES;
        self.changeMobileIDCheckView.verificCodeButton.hidden = NO;
    }
}

- (void)startTimer2 {

    //显示倒计时
    [self.timer2 invalidate];
    self.count2 = 0;
    self.timer2 = [NSTimer scheduledTimerWithTimeInterval:1
                                                   target:self
                                                 selector:@selector(updateTimeLinkNew)
                                                 userInfo:nil
                                                  repeats:YES];
    
    self.changeMobileLinkNewView.countdownLabel.hidden = NO;
    self.changeMobileLinkNewView.verificCodeButton.hidden = YES;
}

- (void)stopTimer2 {
    [self.timer2 invalidate];
    self.changeMobileLinkNewView.countdownLabel.hidden = YES;
    self.changeMobileLinkNewView.verificCodeButton.hidden = NO;
}

- (void)updateTimeLinkNew
{
    self.count2 ++;
    if (self.count2 >= 60) {
        [self stopTimer2];
        return;
    }
    
    self.changeMobileLinkNewView.countdownLabel.text = [NSString stringWithFormat:@"%is", 60-self.count2];
    
    if (self.count2 == 60) {
        self.changeMobileLinkNewView.countdownLabel.hidden = YES;
        self.changeMobileLinkNewView.verificCodeButton.hidden = NO;
    }
}

- (void)navbarBackButtonClickAction:(UIButton*)sender {
    
    if (self.type == LZ_MYCHANGEINFO_TYPE_SETPASSWORD && self.sourceViewType == SourceViewType_LoginVC) {
        // 如果是登录页跳过来的，则点击的时候返回到首页
        [self.navigationController popToRootViewControllerAnimated:YES];
    } else {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (void)navbarSaveButtonClickAction:(UIButton*)sender {
    
    if (self.type == LZ_MYCHANGEINFO_TYPE_NICKNAME) { //更新昵称
        [self changeNickname];
    }
    else if (self.type == LZ_MYCHANGEINFO_TYPE_SETPASSWORD) {    //设置密码
        [self settingPassword];
    }
    else if (self.type == LZ_MYCHANGEINFO_TYPE_CHANGEPASSWORD) { //更改密码
        [self changePassword];
    }
    else if (self.type == LZ_MYCHANGEINFO_TYPE_SETEMAIL) { //设置邮箱
        [self validateNewBindWithType:ValidateNewBindType_Email];
    }
    else if (self.type == LZ_MYCHANGEINFO_TYPE_CHANGEEMAIL) { //更改邮箱
        [self validateNewBindWithType:ValidateNewBindType_Email];
    }
}

//修改昵称
- (void)changeNickname {
    
    if (self.changeNickNameView.textField.text.length <= 0) {
        [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                         andContent:LZLocalizedString(@"enter_nickname", @"")];
        return;
    }
    
    if ([self.changeNickNameView.textField.text isEqualToString:self.currentUserInfo.nickName]) {
        [self.navigationController popViewControllerAnimated:YES];
        return;
    }
    
    [self startLoadingViewForView:self.view loadingViewUserInteractionEnabled:YES];
    
    WS(weakSelf);
    [self.userInfoPresenter userChangeNickname:self.changeNickNameView.textField.text
                                     onSuccess:^(id data) {
                                         DLog(@"修改昵称:%@", data);
                                         
                                         [weakSelf stopLoadingViewForView:weakSelf.view];
                                         
                                         if ([[[data objectForKey:@"data"] objectForKey:@"isExisted"] boolValue] == YES) {
                                             [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                                                              andContent:LZLocalizedString(@"msg_nickname_exists", @"")];
                                         }
                                         else {
                                             [LZRemindView initWithImage:[UIImage imageNamed:@"提示对勾"]
                                                              andContent:LZLocalizedString(@"change_success", @"")];
                                             
                                             weakSelf.currentUserInfo.nickName = weakSelf.changeNickNameView.textField.text;
                                             [[LZUserModel Instance] saveUserInfo:weakSelf.currentUserInfo];
                                             
                                             if (weakSelf.updataUserInfoBlock) {
                                                 weakSelf.updataUserInfoBlock(YES);
                                             }
                                             [weakSelf.navigationController popViewControllerAnimated:YES];
                                         }
                                         
                                     } onFail:^(NSString *fail) {
                                         
                                         [weakSelf stopLoadingViewForView:weakSelf.view];
                                         
                                         [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                                                          andContent:LZLocalizedString(@"change_failed", @"")];
                                         DLog(@"error: %@", fail);
                                     }];
}

//设置密码
- (void)settingPassword {
    
    if (self.setPasswordView.lzNewTextField.textField.text.length <= 0) {
        [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                         andContent:LZLocalizedString(@"enter_password", @"")];
        return;
    } else if (self.setPasswordView.lzNewTextField.textField.text.length > 0 &&
               self.setPasswordView.lzNewTextField.textField.text.length < 6) {
        [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                         andContent:LZLocalizedString(@"enter_password_6_chart", @"")];
        return;
    }
    
    [self startLoadingViewForView:self.view loadingViewUserInteractionEnabled:YES];
    
    WS(weakSelf);
    NSString * strName = nil;
    if (self.sourceViewType == SourceViewType_LoginVC) {
        strName = self.moblieNumber;
    } else {
        strName = self.currentUserInfo.userName;
    }
    
    [self.userInfoPresenter userInitPasswordWithMoblieNum:strName
                                              andPassword:self.setPasswordView.lzNewTextField.textField.text
                                                onSuccess:^(id data) {
                                                    
                                                    [weakSelf stopLoadingViewForView:weakSelf.view];
                                                    
                                                    [LZRemindView initWithImage:[UIImage imageNamed:@"提示对勾"]
                                                                     andContent:LZLocalizedString(@"save_success", @"")];
                                                    
                                                    if (weakSelf.currentUserInfo) {
                                                        weakSelf.currentUserInfo.password = YES;
                                                        [[LZUserModel Instance] saveUserInfo:weakSelf.currentUserInfo];
                                                    }
                                                    
                                                    if (weakSelf.updataUserInfoBlock) {
                                                        weakSelf.updataUserInfoBlock(YES);
                                                    }
                                                    
                                                    if (weakSelf.sourceViewType == SourceViewType_LoginVC) {
                                                        [weakSelf.navigationController popToRootViewControllerAnimated:YES];
                                                    }
                                                    else {
                                                        [weakSelf.navigationController popViewControllerAnimated:YES];
                                                    }
                                                    
                                                } onFail:^(NSString *fail) {
                                                    
                                                    [weakSelf stopLoadingViewForView:weakSelf.view];
                                                    
                                                    [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                                                                     andContent:LZLocalizedString(@"save_failed", @"")];
                                                    DLog(@"error: %@", fail);
                                                }];
}

//更改密码
- (void)changePassword {
    
    if (self.changePasswordView.lzOldTextField.textField.text.length <= 0) {
        [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                         andContent:LZLocalizedString(@"enter_old_password", @"")];
        return;
    } else if (self.changePasswordView.lzOldTextField.textField.text.length > 0 &&
               self.changePasswordView.lzOldTextField.textField.text.length < 6) {
        [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                         andContent:LZLocalizedString(@"enter_password_6_chart", @"")];
        return;
    }
    
    if (self.changePasswordView.lzNewTextField.textField.text.length <= 0) {
        [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                         andContent:LZLocalizedString(@"enter_new_password", @"")];
        return;
    } else if (self.changePasswordView.lzNewTextField.textField.text.length > 0 &&
               self.changePasswordView.lzNewTextField.textField.text.length < 6) {
        [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                         andContent:LZLocalizedString(@"enter_password_6_chart", @"")];
        return;
    }
    
    [self startLoadingViewForView:self.view loadingViewUserInteractionEnabled:YES];
    
    WS(weakSelf);
    [self.userInfoPresenter userChangePassword:self.changePasswordView.lzOldTextField.textField.text
                                andNewPassword:self.changePasswordView.lzNewTextField.textField.text
                                     onSuccess:^(id data) {
                                         DLog(@"更改密码:%@", data);
                                         
                                         [weakSelf stopLoadingViewForView:weakSelf.view];
                                         
                                         [LZRemindView initWithImage:[UIImage imageNamed:@"提示对勾"]
                                                          andContent:LZLocalizedString(@"change_success", @"")];
                                         [weakSelf.navigationController popViewControllerAnimated:YES];
                                     } onFail:^(NSString *fail) {
                                         
                                         DLog(@"error: %@", fail);
                                         
                                         [weakSelf stopLoadingViewForView:weakSelf.view];
                                         
                                         [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                                                          andContent:LZLocalizedString(@"change_failed", @"")];

                                     }];
}

// 绑定邮箱
- (void)requestBindEmailWithIsFirstBind:(BOOL)isFirstBind {
    NSString *oldEmail = nil;
    NSString *newEmail = nil;
    if (isFirstBind) {
        newEmail = self.setEmailView.lzNewTextField.textField.text;
    }
    else {
        oldEmail = self.changeEmailView.lzOldTextField.textField.text;
        newEmail = self.changeEmailView.lzNewTextField.textField.text;
        
        if (oldEmail.length<=0) {
            [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                             andContent:LZLocalizedString(@"change_email_input_old_email", @"")];
            return;
        }
        else if (![oldEmail isEqualToString:self.currentUserInfo.email]) {
            [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                             andContent:LZLocalizedString(@"change_enter_current_email_number", @"")];
            return;
        }
    }
    
    if (newEmail.length<=0) {
        [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                         andContent:LZLocalizedString(@"change_email_input_new_email", @"")];
        return;
    }
    
    [self startLoadingViewForView:self.view loadingViewUserInteractionEnabled:YES];

    WS(weakSelf)
    [self.userInfoPresenter bindEmailWithOldEmail:oldEmail andNewEmail:newEmail onSuccess:^(id data) {
        [weakSelf stopLoadingViewForView:weakSelf.view];
        
        [LZRemindView initWithImage:[UIImage imageNamed:@"提示对勾"]
                         andContent:LZLocalizedString(@"change_success", @"")];

        weakSelf.currentUserInfo.email = newEmail;
        [[LZUserModel Instance] saveUserInfo:weakSelf.currentUserInfo];
        
        if (weakSelf.updataUserInfoBlock) {
            weakSelf.updataUserInfoBlock(YES);
        }
        [weakSelf.navigationController popViewControllerAnimated:YES];
        
    } onFail:^(NSString *fail) {
        [weakSelf stopLoadingViewForView:weakSelf.view];
        
        [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                         andContent:LZLocalizedString(@"change_failed", @"")];
    }];
}

//获取验证码
- (void)getVerifiCodeIdCheck {
    
    if (self.changeMobileIDCheckView.mobileNumTextField.text.length <= 0) {
        [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                         andContent:LZLocalizedString(@"login_enter_mobile", @"")];
        return;
    }
    

    //验证码类型（1注册，2快捷登录，3身份验证，4绑定手机）
    NSString * mobileStr = [NSString stringWithFormat:@"%@%@",
                            self.changeMobileIDCheckView.areaCodeTextField.text,
                            self.changeMobileIDCheckView.mobileNumTextField.text];
    
    if (![mobileStr isEqualToString:self.currentUserInfo.cellphone]) {
        [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                         andContent:LZLocalizedString(@"enter_invalid_mobile", @"")];
        return;
    }
    
    
    [self startLoadingViewForView:self.view loadingViewUserInteractionEnabled:YES];
    
    WS(weakSelf);
    
    [self.userInfoPresenter userGetVerificationCodeType:@"3"
                                            andPhoneNum:mobileStr
                                              onSuccess:^(id data) {
                                                  DLog(@"身份验证 -（3）- 获取验证码:%@", data);
                                                  
                                                  [weakSelf stopLoadingViewForView:weakSelf.view];
                                                  
                                                  //显示倒计时
                                                  [weakSelf startTimer1];
                                                  
                                              } onFail:^(NSString *fail) {
                                                  DLog(@"error: %@", fail);
                                                  [weakSelf stopLoadingViewForView:weakSelf.view];

                                                  if ([fail isEqualToString:@"9999999"]) {
                                                      
//                                                      [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
//                                                                       andContent:LZLocalizedString(@"send_code_maxnum_remind", nil)];
                                                      LZAlertView *alert = [[LZAlertView alloc] initWithContent:LZLocalizedString(@"send_code_maxnum_remind", nil)
                                                                                                       andImage:[UIImage imageNamed:@"error_image"]
                                                                                              cancelButtonTitle:LZLocalizedString(@"confirm", nil)
                                                                                              otherButtonTitles:nil, nil];
                                                      [alert show];
                                                  }
                                                  else {
                                                      
                                                      [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                                                                       andContent:LZLocalizedString(@"vificode_failed", nil)];
                                                  }
                                              }];
}

// 验证要绑定的新手机号是否已存在
- (void)validateNewBindWithType:(ValidateNewBindType)bindType {
    
    NSString *bindName = nil;
    if (bindType == ValidateNewBindType_Mobile) {   // 校验手机号是否存在
        if (self.changeMobileLinkNewView.mobileNumTextField.text.length <= 0) {
            [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                             andContent:LZLocalizedString(@"login_enter_mobile", @"")];
            return;
        }
        
        bindName = [NSString stringWithFormat:@"%@%@",
                                self.changeMobileLinkNewView.areaCodeTextField.text,
                                self.changeMobileLinkNewView.mobileNumTextField.text];
        if (bindName.length < 11) {
            [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                             andContent:LZLocalizedString(@"enter_invalid_mobile", @"")];
            return;
        }
    }
    else if (bindType == ValidateNewBindType_Email) {   // 校验邮箱是否存在
        
        NSString *oldEmail = nil;
        NSString *newEmail = nil;
        
        if (self.type == LZ_MYCHANGEINFO_TYPE_SETEMAIL) { //设置邮箱
            newEmail = self.setEmailView.lzNewTextField.textField.text;
            if (![newEmail isEmailAddress]) {
                [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                                 andContent:LZLocalizedString(@"invalid_email_remind", nil)];
                return;
            }
        }
        else if (self.type == LZ_MYCHANGEINFO_TYPE_CHANGEEMAIL) { //更改邮箱
            oldEmail = self.changeEmailView.lzOldTextField.textField.text;
            newEmail = self.changeEmailView.lzNewTextField.textField.text;
            
            if (![oldEmail isEmailAddress]) {
                [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                                 andContent:LZLocalizedString(@"invalid_old_email_remind", nil)];
                return;
            }
            else if (![newEmail isEmailAddress]) {
                [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                                 andContent:LZLocalizedString(@"invalid_new_email_remind", nil)];
                return;
            }
        }
        
        if (newEmail.length<=0) {
            [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                             andContent:LZLocalizedString(@"change_email_input_new_email", @"")];
            return;
        }
        
        bindName = newEmail;
    }
    
    if (bindName == nil) {
        return;
    }
    
    [self startLoadingViewForView:self.view loadingViewUserInteractionEnabled:YES];
    
    WS(weakSelf);
    
    [self.userInfoPresenter userValidateUserNameWith:bindName onSuccess:^(id data) {
        DLog(@"验证要绑定的新手机号是否已存在:%@", data);
        
        [weakSelf stopLoadingViewForView:weakSelf.view];
        
        if ([[data objectForKey:@"statusCode"] integerValue] == kCodeSuccesss) {
            //不存在，调用获取验证码接口
            if (bindType == ValidateNewBindType_Mobile) {
                [weakSelf getVerifiCodeLinkNew];
            }
            else if (bindType == ValidateNewBindType_Email) {
                if (self.type == LZ_MYCHANGEINFO_TYPE_SETEMAIL) { //设置邮箱
                    [self requestBindEmailWithIsFirstBind:YES];
                }
                else if (self.type == LZ_MYCHANGEINFO_TYPE_CHANGEEMAIL) { //更改邮箱
                    [self requestBindEmailWithIsFirstBind:NO];
                }
            }
        } else {
            //存在，弹出提示
            if (bindType == ValidateNewBindType_Mobile) {
                // 手机号码已存在
                LZAlertView *alert = [[LZAlertView alloc] initWithContent:LZLocalizedString(@"mobile_is_linked", nil) andImage:nil cancelButtonTitle:nil otherButtonTitles:LZLocalizedString(@"confirm", nil),nil];
                [alert show];
            }
            else if (bindType == ValidateNewBindType_Email) {
                // 邮箱已存在存在
                LZAlertView *alert = [[LZAlertView alloc] initWithContent:LZLocalizedString(@"email_is_linked", nil) andImage:nil cancelButtonTitle:nil otherButtonTitles:LZLocalizedString(@"confirm", nil),nil];
                [alert show];
            }
        }
        
    } onFail:^(NSString *fail) {
        DLog(@"error: %@", fail);
        
        [weakSelf stopLoadingViewForView:weakSelf.view];

        [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                         andContent:fail];
    }];
}

// 获取验证码
- (void)getVerifiCodeLinkNew {
    
    //验证码类型（1注册，2快捷登录，3身份验证，4绑定手机）
    if (self.changeMobileLinkNewView.mobileNumTextField.text.length <= 0) {
        [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                         andContent:LZLocalizedString(@"login_enter_mobile", @"")];
        return;
    }
    
    NSString * mobileStr = [NSString stringWithFormat:@"%@%@",
                            self.changeMobileLinkNewView.areaCodeTextField.text,
                            self.changeMobileLinkNewView.mobileNumTextField.text];
//    if (mobileStr.length < 11) {
//        [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
//                         andContent:LZLocalizedString(@"enter_invalid_mobile", @"")];
//        return;
//    }
    
    [self startLoadingViewForView:self.view loadingViewUserInteractionEnabled:YES];
    
    WS(weakSelf);
    [self.userInfoPresenter userGetVerificationCodeType:@"4"
                                            andPhoneNum:mobileStr
                                              onSuccess:^(id data) {
                                                  DLog(@"绑定手机 -（4）- 获取验证码:%@", data);
                                                  
                                                  [weakSelf stopLoadingViewForView:weakSelf.view];
                                                  
                                                  //显示倒计时
                                                  [weakSelf startTimer2];
                                                  
                                              } onFail:^(NSString *fail) {
                                                  DLog(@"error: %@", fail);
                                                  [weakSelf stopLoadingViewForView:weakSelf.view];

                                                  if ([fail isEqualToString:@"9999999"]) {
                                                      
//                                                      [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
//                                                                       andContent:LZLocalizedString(@"send_code_maxnum_remind", nil)];
                                                      LZAlertView *alert = [[LZAlertView alloc] initWithContent:LZLocalizedString(@"send_code_maxnum_remind", nil)
                                                                                                       andImage:[UIImage imageNamed:@"error_image"]
                                                                                              cancelButtonTitle:LZLocalizedString(@"confirm", nil)
                                                                                              otherButtonTitles:nil, nil];
                                                      [alert show];
                                                  }
                                                  else {
                                                      
                                                      [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                                                                       andContent:LZLocalizedString(@"vificode_failed", nil)];
                                                  }
                                                  
                                              }];
}

//身份验证
- (void)validateCellPhone {
    
    if (self.changeMobileIDCheckView.mobileNumTextField.text.length <= 0) {
        [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                         andContent:LZLocalizedString(@"login_enter_mobile", @"")];
        return;
    }
    
    NSString * mobileStr = [NSString stringWithFormat:@"%@%@",
                            self.changeMobileIDCheckView.areaCodeTextField.text,
                            self.changeMobileIDCheckView.mobileNumTextField.text];
    
    if (![mobileStr isEqualToString:self.currentUserInfo.cellphone]) {
        [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                         andContent:LZLocalizedString(@"change_enter_current_mobile_number", @"")];
        return;
    }
    
    NSString * verifiCode = self.changeMobileIDCheckView.verificCodeTextField.text;
    if (verifiCode.length <= 0) {
        [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                         andContent:LZLocalizedString(@"login_enter_verifi_code", @"")];
        return;
    }
    
    [self startLoadingViewForView:self.view loadingViewUserInteractionEnabled:YES];
    
    WS(weakSelf);
    [self.userInfoPresenter userChangeMoblieNumIDCheck:mobileStr
                                         andVerifiCode:verifiCode
                                             onSuccess:^(id data) {
                                                 DLog(@"修改手机 --- 身份验证:%@", data);
                                                 
                                                 [weakSelf stopLoadingViewForView:weakSelf.view];
                                                 
                                                 [weakSelf.timer1 invalidate];
                                                 weakSelf.changeMobileIDCheckView.countdownLabel.hidden = YES;
                                                 weakSelf.changeMobileIDCheckView.verificCodeButton.hidden = NO;
                                                 
                                                 LZMyChangeInfoViewController * vc = [[LZMyChangeInfoViewController alloc] init];
                                                 vc.type = LZ_MYCHANGEINFO_TYPE_LINKNEW_MOBILE;
                                                 [weakSelf.navigationController pushViewController:vc animated:YES];
                                                 [weakSelf lz_removeSelfFromNavigation];
                                                 
                                             } onFail:^(NSString *fail) {
                                                 DLog(@"error: %@", fail);
                                                 
                                                 [weakSelf stopLoadingViewForView:weakSelf.view];
                                                 
                                                 if ([fail isEqualToString:@"0400001"] || [fail isEqualToString:@"0100010"] || [fail isEqualToString:@"0500001"]) { //0100010 验证码错误！
                                                     [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                                                                      andContent:LZLocalizedString(@"enter_invalid_verifi", nil)];
                                                 }
                                                 else if ([fail isEqualToString:@"0500031"]) { //0500031 该用户已被停用，请联系管理员
                                                     LZAlertView *alert = [[LZAlertView alloc] initWithContent:LZLocalizedString(@"mag_account_stopstate", nil)
                                                                                                      andImage:nil
                                                                                             cancelButtonTitle:LZLocalizedString(@"cancel", nil)
                                                                                             otherButtonTitles:nil, nil];
                                                     [alert show];
                                                 }
                                                 else {
                                                     [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                                                                      andContent:fail];
                                                 }
                                             }];
}

//绑定新手机
- (void)linkNewCallPhone {
    
    if (self.changeMobileLinkNewView.mobileNumTextField.text.length <= 0) {
        [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                         andContent:LZLocalizedString(@"login_enter_mobile", @"")];
        return;
    }
    
    NSString * mobileStr = [NSString stringWithFormat:@"%@%@",
                            self.changeMobileLinkNewView.areaCodeTextField.text,
                            self.changeMobileLinkNewView.mobileNumTextField.text];
//    if (mobileStr.length < 11) {
//        [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
//                         andContent:LZLocalizedString(@"enter_invalid_mobile", @"")];
//        return;
//    }
    
    NSString * verifiCode = self.changeMobileLinkNewView.verificCodeTextField.text;
    if (verifiCode.length <= 0) {
        [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                         andContent:LZLocalizedString(@"login_enter_verifi_code", @"")];
        return;
    }
    
    [self startLoadingViewForView:self.view loadingViewUserInteractionEnabled:YES];
    
    WS(weakSelf);
    [self.userInfoPresenter userChangeMoblieNumLinkNew:mobileStr
                                         andVerifiCode:verifiCode
                                             onSuccess:^(id data) {
                                                 DLog(@"修改手机 -- 绑定新手机:%@", data);
                                                 
                                                 [weakSelf stopLoadingViewForView:weakSelf.view];
                                                 
                                                 [weakSelf.timer2 invalidate];
                                                 weakSelf.changeMobileLinkNewView.countdownLabel.hidden = YES;
                                                 weakSelf.changeMobileLinkNewView.verificCodeButton.hidden = NO;
                                                 
                                                 weakSelf.currentUserInfo.cellphone = mobileStr;
                                                 [[LZUserModel Instance] saveUserInfo:weakSelf.currentUserInfo];
                                                 
                                                 for (UIViewController *vc in weakSelf.navigationController.viewControllers) {
                                                     if ([vc isKindOfClass:[LZMyPersonInfoViewController class]]) {
                                                         [self.navigationController popToViewController:vc animated:YES];
                                                         return;
                                                     }
                                                 }
                                                 
                                             } onFail:^(NSString *fail) {
                                                 
                                                 DLog(@"error: %@", fail);
                            
                                                 [weakSelf stopLoadingViewForView:weakSelf.view];
                                                 
                                                 if ([fail isEqualToString:@"0400001"] || [fail isEqualToString:@"0100010"] || [fail isEqualToString:@"0500001"]) { //0100010 验证码错误！
                                                     [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                                                                      andContent:LZLocalizedString(@"enter_invalid_verifi", nil)];
                                                 }
                                                 else if ([fail isEqualToString:@"0500031"]) { //0500031 该用户已被停用，请联系管理员
                                                     LZAlertView *alert = [[LZAlertView alloc] initWithContent:LZLocalizedString(@"mag_account_stopstate", nil)
                                                                                                      andImage:nil
                                                                                             cancelButtonTitle:LZLocalizedString(@"cancel", nil)
                                                                                             otherButtonTitles:nil, nil];
                                                     [alert show];
                                                 }
                                                 else {
                                                     [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                                                                      andContent:fail];
                                                 }
                                             }];
}

// 获取第三方账号信息
- (void)getThirdPartyAccountInfo:(SSDKPlatformType)thirdType {
    WS(weakSelf);
    [SSDKAuthViewStyle setCancelButtonLabelColor:UIColorFromRGB(0x666666, 1)];
    [SSDKAuthViewStyle setTitle:@"Authorize"];
    [SSDKAuthViewStyle setTitleColor:UIColorFromRGB(0x333333, 1)];
    [SSDKAuthViewStyle setStatusBarStyle:UIStatusBarStyleDefault];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
    
    [ShareSDK authorize:thirdType
               settings:nil
         onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error)
     {
         [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
         
         switch (state) {
             case SSDKResponseStateSuccess:
             {
                 DLog(@"授权成功 %@", user);
                 
                 NSMutableDictionary * param_Dict = [NSMutableDictionary dictionary];
                 
                 [param_Dict setObject:user.uid                 forKey:@"partyAccount"];
                 [param_Dict setObject:user.credential.token    forKey:@"partyKey"];
                 
                 if (thirdType == SSDKPlatformTypeFacebook) {
                     [param_Dict setObject:@"1"                forKey:@"type"];
                 } else if (thirdType == SSDKPlatformTypeTwitter) {
                     [param_Dict setObject:@"2"                forKey:@"type"];
                 }
                 
                 DLog(@"第三方登陆获取的信息：%@", param_Dict);
                 [weakSelf requestBindThirdPartyAccount:param_Dict andType:thirdType];
                 
                 
                 break;
             }
             case SSDKResponseStateFail:
             {
                 [weakSelf stopLoadingViewForView:weakSelf.view];
                 [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];

                 DLog(@"授权失败 %@", error);
                 break;
             }
             case SSDKResponseStateCancel:
             {
                 [weakSelf stopLoadingViewForView:weakSelf.view];
                 [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];

                 DLog(@"授权取消");
                 break;
             }
             default:
                 break;
         }
     }];
}

// 绑定第三方账号
- (void)requestBindThirdPartyAccount:(NSMutableDictionary *)param andType:(SSDKPlatformType)thirdType {
    
    [self startLoadingViewForView:self.view loadingViewUserInteractionEnabled:YES];
    
    WS(weakSelf);
    
    [self.userInfoPresenter bindThirdPartyAccountWithParams:param onSuccess:^(id data) {
        
        [weakSelf stopLoadingViewForView:weakSelf.view];
        
        DLog(@"第三方绑定：%@", data);
        
        // 绑定成功
        
        LZThirdPartyAccountModel *model = nil;
        if (weakSelf.currentUserInfo.thirdParty == nil) {
            weakSelf.currentUserInfo.thirdParty = [NSMutableArray array];
        }
        
        if (thirdType == SSDKPlatformTypeFacebook) {
            NSArray *arrResult = [weakSelf.currentUserInfo.thirdParty filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self.type = 1"]];
            if (arrResult.count>0) {
                model = arrResult[0];
            }
            else {
                model = [[LZThirdPartyAccountModel alloc] init];
                [weakSelf.currentUserInfo.thirdParty addObject:model];
            }
            model.type = 1;
        }
        else if (thirdType == SSDKPlatformTypeTwitter) {
            
            NSArray *arrResult = [weakSelf.currentUserInfo.thirdParty filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self.type = 2"]];
            if (arrResult.count>0) {
                model = arrResult[0];
            }
            else {
                model = [[LZThirdPartyAccountModel alloc] init];
                [weakSelf.currentUserInfo.thirdParty addObject:model];
            }
            model.type = 2;
        }
        
        
        model.partyAccount = param[@"partyAccount"];
        model.partyKey = param[@"partyKey"];
        weakSelf.changeLinkAccount.arrThirdParty = weakSelf.currentUserInfo.thirdParty;
        
        [[LZUserModel Instance] saveUserInfo:weakSelf.currentUserInfo];

        [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                         andContent:LZLocalizedString(@"bind_success_remind", nil)];
        
        
    } onFail:^(NSString *fail) {
        [weakSelf stopLoadingViewForView:weakSelf.view];
        [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
                         andContent:LZLocalizedString(@"bind_faild_remind", nil)];
        DLog(@"%@", fail);
    }];
}

// 解绑第三方账号
- (void)requestUnBindThirdPartyWithPartyAccount:(NSString*)partyAccount andType:(SSDKPlatformType)thirdType {
    [self startLoadingViewForView:self.view loadingViewUserInteractionEnabled:YES];
    
    WS(weakSelf);
    
    [self.userInfoPresenter unBindThirdPartyAccountWithPartyAccount:partyAccount onSuccess:^(id data) {
        
        [weakSelf stopLoadingViewForView:weakSelf.view];
        
        DLog(@"第三方解绑：%@", data);
        
        // 绑定成功
        
        LZThirdPartyAccountModel *model = nil;
        if (weakSelf.currentUserInfo.thirdParty == nil) {
            weakSelf.currentUserInfo.thirdParty = [NSMutableArray array];
        }
        
        if (thirdType == SSDKPlatformTypeFacebook) {
            NSArray *arrResult = [weakSelf.currentUserInfo.thirdParty filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self.type = 1"]];
            if (arrResult.count>0) {
                model = arrResult[0];
            }
        }
        else {
            NSArray *arrResult = [weakSelf.currentUserInfo.thirdParty filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self.type = 2"]];
            if (arrResult.count>0) {
                model = arrResult[0];
            }
        }
        
        if (model) {
            [weakSelf.currentUserInfo.thirdParty removeObject:model];
            [[LZUserModel Instance] saveUserInfo:weakSelf.currentUserInfo];
        }
        weakSelf.changeLinkAccount.arrThirdParty = weakSelf.currentUserInfo.thirdParty;
        
    } onFail:^(NSString *fail) {
        [weakSelf stopLoadingViewForView:weakSelf.view];
        if ([fail isEqualToString:@"0500033"]) {        // 第三方账户未绑定电话或邮箱，不能解绑
//            [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"]
//                             andContent:LZLocalizedString(@"unbind_thirdparty_faild_remind", nil)];
            LZAlertView *alert = [[LZAlertView alloc] initWithContent:LZLocalizedString(@"unbind_thirdparty_faild_remind", nil)
                                                             andImage:[UIImage imageNamed:@"error_image"]
                                                    cancelButtonTitle:LZLocalizedString(@"confirm", nil)
                                                    otherButtonTitles:nil, nil];
            [alert show];
            
        }
        DLog(@"%@", fail);
    }];
}

#pragma mark - Setter/Getter

- (LZMyChangeNickNameView *)changeNickNameView {
    
    if (_changeNickNameView == nil) {
        _changeNickNameView = [[LZMyChangeNickNameView alloc] initWithIsPassword:NO];
    }
    
    return _changeNickNameView;
}

- (LZMyChangeMobileView *)changeMobileIDCheckView {
    
    if (_changeMobileIDCheckView == nil) {
        _changeMobileIDCheckView = [[LZMyChangeMobileView alloc] initWithType:LZ_CHANGEMOBLIE_TYPE_IDCHECK];
        
        WS(weakSelf)
        _changeMobileIDCheckView.clickAreaCodeTextFieldBlock = ^(UILabel *label) {
            LZAreaCodeViewController *vc = [[LZAreaCodeViewController alloc] init];
            [weakSelf.navigationController pushViewController:vc animated:YES];
            vc.SelectedAreaCodeBlock = ^(NSString *areaCode) {
                label.text = areaCode;
            };
        };
    }
    
    return _changeMobileIDCheckView;
}

- (LZMyChangeMobileView *)changeMobileLinkNewView {
    
    if (_changeMobileLinkNewView == nil) {
        _changeMobileLinkNewView = [[LZMyChangeMobileView alloc] initWithType:LZ_CHANGEMOBLIE_TYPE_LINKNEW];
        
        WS(weakSelf)
        _changeMobileLinkNewView.clickAreaCodeTextFieldBlock = ^(UILabel *label) {
            LZAreaCodeViewController *vc = [[LZAreaCodeViewController alloc] init];
            [weakSelf.navigationController pushViewController:vc animated:YES];
            vc.SelectedAreaCodeBlock = ^(NSString *areaCode) {
                label.text = areaCode;
            };
        };
    }
    
    return _changeMobileLinkNewView;
}

- (LZMyChangeLinkAccount *)changeLinkAccount {
    
    if (_changeLinkAccount == nil) {
        _changeLinkAccount = [[LZMyChangeLinkAccount alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64) style:UITableViewStyleGrouped];
        _changeLinkAccount.arrThirdParty = self.currentUserInfo.thirdParty;
    }
    
    return _changeLinkAccount;
}

- (LZMyChangeInfoView *)setPasswordView {
    
    if (_setPasswordView == nil) {
        _setPasswordView = [[LZMyChangeInfoView alloc] initWithTextFieldIsSecure:YES];
        _setPasswordView.type = LZ_CHANGEINFO_VIEW_TYPE_SET;
        _setPasswordView.lzNewLabel.text    = LZLocalizedString(@"login_password", @"");//@"Password";
        _setPasswordView.lzNewTextField.textField.placeholder = LZLocalizedString(@"enter_password", @"");//@"Please enter password";
    }
    
    return _setPasswordView;
}

- (LZMyChangeInfoView *)changePasswordView {
    
    if (_changePasswordView == nil) {
        _changePasswordView = [[LZMyChangeInfoView alloc] initWithTextFieldIsSecure:YES];
        _changePasswordView.type = LZ_CHANGEINFO_VIEW_TYPE_CHANGE;
        _changePasswordView.lzOldLabel.text    = LZLocalizedString(@"old_password", @"");//@"Old password";
        _changePasswordView.lzNewLabel.text        = LZLocalizedString(@"new_password", @"");//@"New password";
        _changePasswordView.lzNewTextField.textField.placeholder = LZLocalizedString(@"enter_new_password", @"");//@"Please enter new password";
        _changePasswordView.lzOldTextField.textField.placeholder = LZLocalizedString(@"enter_old_password", @"");//@"Please enter old password";
    }
    
    return _changePasswordView;
}

- (LZMyChangeInfoView *)setEmailView {
    
    if (_setEmailView == nil) {
        _setEmailView = [[LZMyChangeInfoView alloc] initWithTextFieldIsSecure:NO];
        _setEmailView.type = LZ_CHANGEINFO_VIEW_TYPE_SET;
        _setEmailView.lzNewLabel.text    = LZLocalizedString(@"change_email_new_email", @"");//@"Password";
        _setEmailView.lzNewTextField.textField.placeholder = LZLocalizedString(@"change_email_input_new_email", @"");
        _setEmailView.subLabel.text = @"";
    }
    
    return _setEmailView;
}

- (LZMyChangeInfoView *)changeEmailView {
    
    if (_changeEmailView == nil) {
        _changeEmailView = [[LZMyChangeInfoView alloc] initWithTextFieldIsSecure:NO];
        _changeEmailView.type = LZ_CHANGEINFO_VIEW_TYPE_CHANGE;
        _changeEmailView.lzOldLabel.text    = LZLocalizedString(@"change_email_old_email", @"");//@"Old e-Mail";
        _changeEmailView.lzNewLabel.text        = LZLocalizedString(@"change_email_new_email", @"");//@"New e-Mail";
        _changeEmailView.lzNewTextField.textField.placeholder = LZLocalizedString(@"change_email_input_new_email", @"");
        _changeEmailView.lzOldTextField.textField.placeholder = LZLocalizedString(@"change_email_input_old_email", @"");
        _changeEmailView.subLabel.text = @"";
    }
    
    return _changeEmailView;
}

- (LZActionSheet*)sheetView {
    if (_sheetView) {
        return _sheetView;
    }
    
    LZActionSheet *sheet = [[LZActionSheet alloc] initWithFrame:self.navigationController.view.bounds];
    _sheetView = sheet;
    [self.navigationController.view addSubview:_sheetView];
    
    return _sheetView;
}

- (void)showUnBindThirdPartyAlertWithPartyAccount:(NSString*)partyAccount andType:(SSDKPlatformType)thirdType {
    LZAlertView *alert = [[LZAlertView alloc] initWithContent:LZLocalizedString(@"change_unlink_remind", nil) andImage:nil cancelButtonTitle:LZLocalizedString(@"cancel", nil) otherButtonTitles:LZLocalizedString(@"change_unlink", nil),nil];
    [alert show];
    
    WS(weakSelf)
    alert.clickButtonIndexBlock = ^(NSInteger index) {
        if (index == 1) {
            [weakSelf requestUnBindThirdPartyWithPartyAccount:partyAccount andType:thirdType];
        }
    };
    
}

@end
